package cn.edu.flink.scala.tutorial.wordcount

import org.apache.flink.streaming.api.scala._

object BoundedStreamWordCount {
  def main(args: Array[String]): Unit = {
    // 创建流执行环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)
    //读取文本文件
    val lineDS = env.readTextFile("input/word.txt")
    //对数据进行格式转换
    val wordAndOne = lineDS.flatMap(_.split(" ")).map(r => (r, 1))
    //对数据进行分组
    val wordAndOneKS = wordAndOne.keyBy(_._1)
    //对分组数据进行聚合
    val result = wordAndOneKS.sum(1)
    //打印结果
    result.print()
    //执行任务
    env.execute()

  }
}
